package com.lzl.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ContainerSingleton {

    private static  Map<String,Object> ioc = new ConcurrentHashMap<String, Object>();

    private ContainerSingleton(){}

    public static Object getInstance(String className){
        synchronized (ioc){
            if(!ioc.containsKey(className)){
                Object o = null;
                try{
                    o = Class.forName(className).newInstance();
                    ioc.put(className,o);
                }catch (Exception e){
                    e.printStackTrace();
                }
                return o;
            }else{
                return ioc.get(className);
            }
        }
    }
}
